function changecode(){

	document.getElementById("code1").src="CheckCodeServlet?r"+new Date();

	
}
function changeimg(file){
	var reader=new FileReader();
	var img=document.getElementById("showimg")

	if (file.value.indexOf("jpg")>file.value.length-4||file.value.indexOf("png")>file.value.length-4) {
		
		//读取File对象的数据
		reader.onload = function(evt){
			img.src = evt.target.result;
		}
		img.src=reader.readAsDataURL(file.files[0]);
	}else{
		alert("只支持jpg,png格式图片");
		file.value=null;
	}

}

//创建后台生成手机验证码对象:
var phonerescode="";
function changebutton(){
	//60s倒计时
	var phonecode=document.getElementById("phonecode");
	var time=60;
	var timer=setInterval(function(){
		time--;
		phonecode.setAttribute("disabled",true);
		phonecode.value=time+"s后重新获取";
		if (time==0) {
			time=60;
			clearInterval(timer);
			phonecode.removeAttribute("disabled");
			phonecode.value="获取验证码";

		}
		
	},1000)
	
}
function phonegetcode(){
	if (checkphone()==true) {
		changebutton();
		var phone=document.getElementById("phone").value;
		//创建ajax对象
		var ajaxObject;
		//判断浏览器
			if (window.XMLHttpRequest) {//新浏览器
				ajaxObject=new XMLHttpRequest();
			}else{
				ajaxObject=new ActiveXObject("Microsoft.XMLHTTP");
			}
		//用ajax引擎发送请求对象
		ajaxObject.open("get","SmsServlet?phone="+phone,true);
		//发送请求
		ajaxObject.send();
		//调用回调函数
			ajaxObject.onreadystatechange=function(){
			//判断请求是否完成和响应是否正常
			if(ajaxObject.readyState==4&&ajaxObject.status==200){
				//用ajax引擎对象接收响应结果
				var res=ajaxObject.responseText;
				phonerescode=res;
				
				
				
			}
		}
	}

	
	


	
}
	
function checkaccount(){
	var saccount=document.getElementById("account");
	var saccounthint=document.getElementById("accounthint");

	if(saccount.value==""){
		saccounthint.innerText="用户名不能为空";
		return false
	}else{

		return true
	}

}
function checkpwd(){
	var password=document.getElementById("password");
	var passwordhint=document.getElementById("pwdhint");
	if(password.value==""){
		passwordhint.innerText="密码不能为空";
		return false
	}else{
		passwordhint.innerText="√";
		return true
	}
	
}
function checkpwd2(){
	var password=document.getElementById("password");
	var password2=document.getElementById("password2");

	var passwordhint2=document.getElementById("pwdhint2");
	if(password2.value==""){
		passwordhint2.innerText="密码不能为空";
		return false;
	}else if(password2.value!=password.value) {
		passwordhint2.innerText="两次输入密码不一致";
		return false;
	}else{
		passwordhint2.innerText="√";
		return true;
	}
	
}
function checkaccount2(){
	var account=document.getElementById("account");
	var accounthint=document.getElementById("accounthint");
	var flag;
	if(checkaccount()==true){
		//创建ajax对象
		var ajaxObject;
		//判断浏览器
			if (window.XMLHttpRequest) {//新浏览器
				ajaxObject=new XMLHttpRequest();
			}else{
				ajaxObject=new ActiveXObject("Microsoft.XMLHTTP");
			}
		//用ajax引擎发送请求对象
		ajaxObject.open("get","AdminServlet?action=queryByAccount&account="+account.value,true);
		//发送请求
		ajaxObject.send();
		//调用回调函数
			ajaxObject.onreadystatechange=function(){
			//判断请求是否完成和响应是否正常
			if(ajaxObject.readyState==4&&ajaxObject.status==200){
				//用ajax引擎对象接收响应结果
				var res=ajaxObject.responseText;
				flag=eval("("+res+")");
				if (flag.flag==false) {

					accounthint.innerText="√";
						return true

				} else{

					accounthint.innerText="该账号存在";
					return false
				}
				
				
			}
		}

	}

	

}


function checkphone(){
	var regphone="^[1][3-9][0-9]{9}$";
	var phone=document.getElementById("phone");
	var phonehint=document.getElementById("phonehint")
	if(phone.value==""){
		phonehint.innerText="手机号不能为空"
		return false
	}else if(!phone.value.match(regphone)){
		phonehint.innerText="请填写正确的手机号"
		
		return false
	}else{
		phonehint.innText="√"
		return true
	}
	
}
function checkphonecode(){
	var regphone="^[0-9]{6}$";
	var phonecode1=document.getElementById("phoneincode1");
	var phoneincodehint=document.getElementById("phoneinhint");

	if(phonecode1.value==""){
		phoneincodehint.innerText="短信验证码不能为空";
		return false
	}else if(!phonecode1.value.match(regphone)){
		phonehint.innerText="请填写6位数字验证码";
		return false
	}else if(phonerescode!=phonecode1.value) {

		phoneincodehint.innerText="验证码错误";
		return false
	}else{
		phoneincodehint.innerText="√";
		return true
	}
}
function checkcode(){
	var regcode="^[0-9a-zA-z]{4}$";
	var codeString=document.getElementById("code1");
	var codehint=document.getElementById("codehint");
	if(codeString.value==""){
		codehint.innerText="验证码不能为空";

		return false
	}else if(!codeString.value.match(regcode)){
		codehint.innerText="请填写4位验证码";

		return false
	}else{
		codehint.innerText="√";
		return true
	}
	
}
function checkname(){
	var name=document.getElementById("name").value;
	var namehint=document.getElementById("namehint");
	if(name==""){
		namehint.innerText="姓名不能为空";
		return false;
	}else{
		namehint.innerText="√";
		return true;
	}
}
function checkall(){
	//checkphonecode()==true手机验证码判断
	//checkaccount2()==true&
	if (checkpwd()==true&checkname()==true&checkphone()==true&checkcode()==true){
		
		return true;
		
	} else{
		alert("请按要求填写");
		return false;
	}
}